//
//  blostView.m
//  OurRelaxDemo
//
//  Created by apple on 15/7/3.
//  Copyright (c) 2015年 于宾尧. All rights reserved.
//

#import "blostView.h"
#include "Player.h"
@implementation blostView

-(void)dealloc
{
    [_timer release];
    [_emitterAnimation release];
    [_emitterAnimation2 release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //self.imageView = [[UIImageView alloc]initWithFrame:self.bounds];
        self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height - 125)];
        //NSLog(@"%@",self.imageView);
        [self addSubview:self.imageView];
        self.imageView.image = [UIImage imageNamed:@"background1.jpg"];
        self.imageView.backgroundColor = [UIColor clearColor];
        self.imageView.userInteractionEnabled = YES;
        [_imageView release];
        

        
    self.emitterAnimation2 = [[KLEmitter alloc] initWithFrame:frame];
        //    emitterAnimation2.showColor = [UIColor blackColor];
        [self.emitterAnimation2 makeEmitter];
        [self.imageView addSubview:self.emitterAnimation2];
        
        self.emitterAnimation = [[KLEmitter alloc] initWithFrame:frame];
        self.emitterAnimation.showColor = [UIColor whiteColor];
        [self.emitterAnimation makeEmitter];
//            self.emitterAnimation.backgroundColor = [UIColor redColor];
        [self.imageView addSubview:self.emitterAnimation];
        
        
        self.timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(readMusicPeak) userInfo:nil repeats:YES];
        
        
    }
    return self;
}
/**
 *    读取音乐数据
 */
-(void)readMusicPeak{
    #pragma mark 这是动画效果的参数
//    
//  CGFloat aa = 40 * (([[Player shareDataHandle].player averagePowerInDecibelsForChannel:0] + 70) / 20);
    CGFloat aa = [[Player shareDataHandle].player averagePowerInDecibelsForChannel:0];
//    NSLog(@"*********%f", (aa * 4 + 60 * 2));
    
    [self.emitterAnimation animationWith:(aa * 4 + 60 * 2 + 60)];
}
- (void)changeAction
{

//     NSInteger num = arc4random() % self.colorArr.count;
    self.emitterAnimation.showColor = [UIColor yellowColor];

}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
